package com.run2code.design.behavioral.visitor;

/**
 * 书籍类，实现了Product接口
 * 关注公众号【奔跑的码畜】，一起进步不迷路
 *
 * @author 第七人格
 * @date 2024/06/25
 */
public class Book implements Product {
    /**
     * 书籍的标题
     */
    private String title;
    /**
     * 书籍的作者
     */
    private String author;
    /**
     * 书籍的价格
     */
    private double price;

    /**
     * 书籍的构造函数，用于初始化书籍的信息
     * @param title
     * @param author
     * @param price
     */
    public Book(String title, String author, double price) {  
        this.title = title;  
        this.author = author;  
        this.price = price;  
    }

    /**
     * 实现Product接口的accept方法，用于接受访问者
     * @param visitor
     */
    @Override  
    public void accept(ProductVisitor visitor) {
        // 调用访问者的visitBook方法，传入当前书籍对象
        visitor.visitBook(this);
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}